<template>
   <div class="app-container">
      <el-form inline>
         <el-form-item label="下载地址：">
            <el-input v-model="dpwnUrl" style="width: 400px"></el-input>
         </el-form-item>
         <el-form-item>
            <el-button type="primary" @click="upDateUrl">更新地址</el-button>
         </el-form-item>
      </el-form>
   </div>
</template>
<script>
import { onMounted, reactive, toRefs } from "vue"
import { getappDownUrl, updateappDownUrl } from "@/api/system/config.js"
import { ElMessage } from "element-plus"

export default {
   name: "downloadConfig",
   setup() {
       const data = reactive({
           title: "下载配置",
           dpwnUrl: '',
           id: ''
       })

       const upDateUrl = () => {
         updateappDownUrl({
            id: data.id,
            appDownUrl: data.dpwnUrl
         }).then(res=>{
            if(res.code == 200){
               ElMessage.success('更新成功')
            }
            else{
               ElMessage.error('更新失败')
            }
         })
       }

       const query = () => {
         getappDownUrl().then(res=>{
            if(res.code == 200){
               data.dpwnUrl = res.data.url
               data.id = res.data.id
            }else{
               ElMessage.error('获取失败')
            }
         })
       }

       onMounted(()=>{
         query()
       })

       return {
           ...toRefs(data),
           upDateUrl
       }
   }
};
</script>
<style lang="scss" scoped>

</style>